﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FoodLists.aspx.cs" Inherits="Page_Customer_FoodLists" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <title>营养餐</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <script src="../../Scripts/jquery-1.8.0.min.js"></script>
    <script src="../../Scripts/jquery.form.js"></script>
    <script src="../../Scripts/amazeui.min.js"></script>
    <link href="../../CSS/amazeui.min.css" rel="stylesheet" />
    <link href="../../CSS/style.css" rel="stylesheet" />
    <%--layui--%>
    <link href="../../layui/css/layui.css" rel="stylesheet" />
    <script src="../../layui/laydate.js"></script>
    <script src="../../layui/layui.js"></script>
    <style>
        .radio {
            width: 20px;
            height: 20px;
            vertical-align: text-bottom;
            margin-bottom: 2px;
            *margin-bottom: -2px;
        }

        .mask {
            position: absolute;
            top: 0px;
            filter: alpha(opacity=60);
            background-color: #777;
            z-index: 1002;
            left: 0px;
            opacity: 0.5;
            -moz-opacity: 0.5;
        }
    </style>
</head>
<body>

    <header data-am-widget="header" class="am-header am-header-default sq-head ">
        <div class="am-header-right am-header-nav">
            <img src="../../Content/syzyy/img/banner1.jpg" />
        </div>
        <input type="hidden" class="meanIDList">
    </header>
    <div class="content-list" id="outer">

        <div class="list-left ng-cloak" id="tab">
            <li class="current" id="li-1" state="-1" onclick="FoodTypeClick('-1')"><a style="position: relative;">餐次选择</a></li>
        </div>

        <div class="list-right" id="content">
            <ul class="list-pro">
            </ul>
            <form class="layui-form">
                <div class="layui-form-item" style="margin-top: 50px">
                    <label class="layui-form-label" style="float: left; display: block; padding: 9px 0; width: 80px; font-weight: 400; text-align: right;">
                        就餐日期
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="test1" placeholder="yyyy-MM-dd">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">餐次</label>
                    <div class="layui-input-block">
                        <select lay-filter="interest" lay-verify="type" name="interest" class="foodpart">
                            <option value="0">早餐</option>
                            <option value="1">中餐</option>
                            <option value="2">晚餐</option>
                        </select>
                    </div>
                </div>
            </form>
        </div>

        <div class="list-right" id="contents" style="display: none;">
        </div>
    </div>
    <!--底部-->
    <div style="height: 100px;"></div>
    <%if (Model != null && !string.IsNullOrEmpty(Model.PatientPatiID))
        {%>
    <div class="fix-bot">
        <span class="list-js">合计：<i class="foodNum"></i><em>份</em></span>
        <span class="list-jsk">选好了</span>
    </div>
    <% } %>


    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
        <div class="am-modal-dialog">
            <div class="am-modal-bd" style="height: 80px; line-height: 80px;">您确定要清空饮品吗？</div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                <span class="am-modal-btn" data-am-modal-confirm>确定</span>
            </div>
        </div>
    </div>
    <div style="text-align: center; display: none;" id="mask" class="mask">
        <img src="/images/m-tips-loading.gif" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);" />
    </div>
    <script>
        layui.use('form', function () {
            var form = layui.form();

            form.on('select(interest)', function (data) {
                var foodpart = $(".foodpart").val();
                var date = $("#test1").val();
                GetFood(date, foodpart);
            });

        });





        //删除提示信息   
        $(function () {
            $('#doc-modal-list').find('.am-icon-close').add('#doc-confirm-toggle').
              on('click', function () {
                  $('#my-confirm').modal({
                      relatedTarget: this,
                      onConfirm: function (options) {
                          var $link = $(this.relatedTarget).prev('a');
                          //var msg = $link.length ? '你要删除的饮品 为 ' + $link.data('id') :
                          //  '确定了';
                          //        alert(msg);

                      },
                      onCancel: function () {
                      }
                  });
              });

            $(".list-jsk").click(function () {
                $(".list-jsk").hide();
                var meanIdlist = $(".meanIDList").val();
                var date = $("#test1").val();
                var foodpart = $(".foodpart").val();

                if (meanIdlist == "") {
                    layer.msg("菜品为空", {
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        $(".list-jsk").show();
                    });
                    return;
                }

                $.post("/Handler/FoodHandler.ashx?Action=OrderDinner", { MeanIDList: meanIdlist, FoodDate: date, FoodPart: foodpart, CardID: '<%=Model.PatientPatiID%>' }, function (data) {
                    var list = eval("(" + data + ")");
                    if (list.status == 1) {
                        layer.msg(list.info, {
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            window.location.href = "FoodListDetial.aspx";
                        });
                    }
                    else {
                        layer.msg(list.info, {
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            $(".list-jsk").show();
                        });
                    }
                });
            })
        })

        $(function () {
            GetShopOrderType();
        })

        //获取当天菜单
        function GetShopOrderType() {
            var a = new Date();
            var mindate = a.getFullYear() + "-" + (a.getMonth() + 1) + "-" + a.getDate();
            var maxdate = a.getFullYear() + "-" + (a.getMonth() + 1) + "-" + (a.getDate() + 1);
            lay('#version').html('-v' + laydate.v);

            //执行一个laydate实例
            laydate.render({
                elem: '#test1', //指定元素
                value: mindate,
                min: mindate,
                max: maxdate,
                done: function (value, date, endDate) {//控件选择完毕后的回调---点击日期、清空、现在、确定均会触发。
                    var foodpart = $(".foodpart").val();
                    GetFood(value, foodpart);
                }
            });

            var foodPart = $(".foodpart").val();
            var FoodDate = mindate;

            GetFood(FoodDate, foodPart);
        }


        function FoodTypeClick(foodtype) {
            $('#contents ul').css('display', 'none');
            var $li = $('#tab li').removeClass();
            $("#li" + foodtype).addClass('current');
            if (foodtype == "-1") {
                $('#content').css('display', 'block');
                $("#li-1").addClass('current');
                $('#contents').hide();
            } else {
                $('#content').css('display', 'none');
                $('#contents').show();
                $('#listpro' + foodtype).show();
            }
        }

        function FoodAdd(meadId, foodtype) {
            var self = $("#increase" + meadId);
            var current_num = parseInt(self.siblings('input').val());
            if (current_num == 1) {
                return;
            }
            var meanIDList = $(".meanIDList" + foodtype).val();
            if (meanIDList.replace(/,/g, "") != "") {
                return;
            }

            if ($(".meanIDList11").length > 0 && $(".meanIDList11").val().replace(/,/g, "") != "") {
                layer.msg("该食物不可选择，已选择流食");
                return;
            }

            current_num += 1;
            if (current_num > 0) {
                self.siblings(".decrease").fadeIn();
                self.siblings(".text_box").fadeIn();
            }
            self.siblings('input').val(current_num);

            $(".meanIDList" + foodtype).val(meadId);


            $(".meanIDList").val($(".meanIDList").val() + meadId + ",")

            if ($(".foodNum").text() == "") {
                $(".foodNum").text(1);
            } else {
                $(".foodNum").text(parseInt($(".foodNum").text()) + 1);
            }

            if ($(".meanIDList11").length > 0 && foodtype == "11") {
                $(".meanIDList").val(meadId);
                $(".foodNum").text(1);
            }

        }

        function Food(meadId, foodtype) {
            var self = $("#decrease" + meadId);
            var current_num = parseInt(self.siblings('input').val());
            if (current_num > 0) {
                current_num -= 1;
                if (current_num < 1) {
                    self.fadeOut();
                    self.siblings(".text_box").fadeOut();
                }
                self.siblings('input').val(current_num);
                $(".meanIDList" + foodtype).val("");
                var meanIDList = $(".meanIDList").val()
                $(".meanIDList").val(meanIDList.replace(meadId + ",", ""))
                $(".foodNum").text(parseInt($(".foodNum").text()) - 1);
                //update_item(self.siblings('input').data('item-id'));

                if ($(".meanIDList11").length > 0 && foodtype == "11") {
                    var foodpart = $(".foodpart").val();
                    var date = $("#test1").val();
                    $.post("/Handler/FoodHandler.ashx?Action=GetFoodsBiChi", { FoodPart: foodpart, FoodDate: date }, function (data) {
                        var list = eval("(" + data + ")");
                        if (list != "undefined") {
                            var meanid = '';
                            for (var i = 0; i < list.length; i++) {
                                {
                                    meanid += list[i] + ","
                                }
                                $(".meanIDList").val(meanid);
                                $(".foodNum").text(list.length);
                            }
                        }
                    });
                }
                
            }
        }

        function InitFood(foodtype, date) {
            var foodPart = $(".foodpart").val();
            var FoodDate = date;
            $.post("/Handler/FoodHandler.ashx?Action=GetFoodType", { FoodPart: foodPart, FoodDate: FoodDate, FoodType: foodtype }, function (data) {
                if (data == "" || typeof (eval("(" + data + ")").List) == "undefined") { }
                else {
                    var list = eval("(" + data + ")").List;
                    if (typeof (list) != "undefined") {
                        var allli = "";
                        for (var i = 0; i < list.length; i++) {
                            var html = "";
                            var html1 = "<li>"
                                         + "<a href='detail.html'>"
                                              + "<img src='../../Images/dyl_1.png' class='list-pic' />"
                                           + "</a>"
                                          + "<div class='shop-list-mid'>"
                                              + "<div class='tit'><a href='detail.html'>{foodName}</a></div>"
                                          + "</div>";

                            var html2 = "<div class='list-cart'>"
                                             + "<div class='d-stock'>"
                                                 + "<a class='decrease' style='display: inline;'>-</a>"
                                                 + "<input id='{num}' readonly='' class='text_box' name='' type='text' style='display: inline;' value='1'>"
                                                 + "<a class='increase'>+</a>"
                                            + "</div>"
                                      + "</div>"
                                    + "</li>";

                            var html3 = "<div class='list-cart'>"
                                             + "<div class='d-stock'>"
                                                 + "<a class='decrease' id='{decrease}' onclick=Food('{meanId1}','" + foodtype + "')>-</a>"
                                                 + "<input id='{num}' readonly='' class='text_box' name='' type='text' value='0'>"
                                                 + "<a class='increase' id='{increase}' onclick=FoodAdd('{meanId}','" + foodtype + "')>+</a>"
                                            + "</div>"
                                      + "</div>"
                                    + "</li>";

                            if (list[i].FOODSTATE == "0") {
                                html = html1 + html3;
                            } else {
                                html = html1 + html2;
                            }
                            allli += html.replace(/{foodName}/, list[i].FOODALLNAME).replace(/{meanId}/, list[i].MEANID).replace(/{meanId1}/, list[i].MEANID).replace(/{increase}/, "increase" + list[i].MEANID).replace(/{decrease}/, "decrease" + list[i].MEANID).replace(/{num}/, "num" + list[i].MEANID);
                        }
                        var totalHtml = "<ul class='list-pro' style='display: none;' id='listpro" + foodtype + "'><input type=‘hidden’ class='meanIDList" + foodtype + "'>" + allli + "</ul>";
                        $("#contents").append(totalHtml);
                        hideMask();
                    }
                }

            })
        }


        function GetFood(FoodDate, foodPart) {
            showMask();
            $("#tab").html("");
            $("#contents").html("");
            $.post("/Handler/FoodHandler.ashx?Action=GetFoodList", { FoodPart: foodPart, FoodDate: FoodDate }, function (data) {
                var list = eval("(" + data + ")");
                if (list != "undefined") {
                    var allli = "";
                    for (var i = 0; i < list.length; i++) {
                        var html = "<li class='' id='{divId}'  state='{foodTypeId}'  onclick=FoodTypeClick('{foodTypeId1}')><a style='position: relative;'>{foodType}</a></li>";

                        var typeName = "";
                        if (list[i] == "00") {
                            typeName = "主食";
                        }
                        if (list[i] == "01") {
                            typeName = "鸡蛋";
                        }
                        if (list[i] == "02") {
                            typeName = "汤";
                        }
                        if (list[i] == "03") {
                            typeName = "粥";
                        }
                        if (list[i] == "04") {
                            typeName = "牛奶";
                        }
                        if (list[i] == "05") {
                            typeName = "豆浆";
                        }
                        if (list[i] == "06") {
                            typeName = "主菜";
                        }
                        if (list[i] == "07") {
                            typeName = "副菜";
                        }
                        if (list[i] == "08") {
                            typeName = "素食";
                        }
                        if (list[i] == "09") {
                            typeName = "半流食";
                        }
                        if (list[i] == "10") {
                            typeName = "软食";
                        }
                        if (list[i] == "11") {
                            typeName = "流食";
                        }
                        if (list[i] == "12") {
                            typeName = "饮品";
                        }
                        if (list[i] == "13") {
                            typeName = "月子餐";
                        }
                        allli += html.replace(/{foodTypeId}/, list[i]).replace(/{foodType}/, typeName).replace(/{divId}/, "li" + list[i]).replace(/{foodTypeId1}/, list[i]);
                        InitFood(list[i], FoodDate);

                    }

                    $("#tab").append("<li class='current' id='li-1' state='-1' onclick=FoodTypeClick('-1')><a style='position: relative;'>餐次选择</a></li>" + allli);

                }
            });
            $.post("/Handler/FoodHandler.ashx?Action=GetFoodsBiChi", { FoodPart: foodPart, FoodDate: FoodDate }, function (data) {
                var list = eval("(" + data + ")");
                if (list != "undefined") {
                    var meanid = '';
                    for (var i = 0; i < list.length; i++) {
                        {
                            meanid += list[i] + ","
                        }
                        $(".meanIDList").val(meanid);
                        $(".foodNum").text(list.length);
                    }
                }
            });
        }

        //显示遮罩层    
        function showMask() {
            $("#mask").css("height", $(document).height());
            $("#mask").css("width", $(document).width());
            $("#mask").show();
        }
        //隐藏遮罩层  
        function hideMask() {

            $("#mask").hide();
        }



    </script>
</body>
</html>
